package com.gm.server.voice.core.runable;

import com.gm.server.voice.utils.AudioUtils;

import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.TargetDataLine;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

/**
 * 采集音频并发送
 */
public class SendAudio implements Runnable{

    private Socket socket;
    private InputStream inputStream;

    public SendAudio(Socket socket, InputStream inputStream) {
        this.socket = socket;
        this.inputStream = inputStream;
    }

    // 发送
    @Override
    public void run() {
        try {
            OutputStream out = socket.getOutputStream();
            byte[] buffer = new byte[1024];
            int bytesRead;
            while ((bytesRead = inputStream.read(buffer)) != -1) {
                out.write(buffer, 0, bytesRead);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
